package com.lj.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lj.mapper.ManagerljMapper;
import com.lj.pojo.*;
import com.lj.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    ManagerljMapper managerljMapper;
    @Override
    public Managerlj login(String name, String pwd) {
        ManagerljExample example=new ManagerljExample();
        example.createCriteria().andManagerIdEqualTo(name);
        List<Managerlj> list=managerljMapper.selectByExample(example);
        if(list.size()>0){
            Managerlj managerlj=list.get(0);
            if(managerlj.getManagerPassword().equals(pwd)){
                return managerlj;
            }
        }
        return null;
    }

    @Override
    public PageInfo selectManager(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        ManagerljExample example=new ManagerljExample();
        example.setOrderByClause("manager_id desc");
        List<Managerlj> list=managerljMapper.selectByExample(example);
        PageInfo<Managerlj> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int insertManager(Managerlj managerlj) {
        return managerljMapper.insert(managerlj);
    }

    @Override
    public int delete(String id) {
        return managerljMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Managerlj getById(String id) {
       return managerljMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(Managerlj managerlj) {
        return managerljMapper.updateByPrimaryKey(managerlj);
    }
}
